package com.hubspot.deploy;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import java.util.Optional;

@Schema(
  description = "A file with name `filename` containing the signature (e.g. gpg signature) for an artifact with the specified `artifactFilename`. Used to verify the validity of the artifact being downloaded"
)
public class S3ArtifactSignature extends S3Artifact {
  private final String artifactFilename;

  @JsonCreator
  public S3ArtifactSignature(
    @JsonProperty("name") String name,
    @JsonProperty("filename") String filename,
    @JsonProperty("md5sum") Optional<String> md5sum,
    @JsonProperty("filesize") Optional<Long> filesize,
    @JsonProperty("s3Bucket") String s3Bucket,
    @JsonProperty("s3ObjectKey") String s3ObjectKey,
    @JsonProperty("artifactFilename") String artifactFilename,
    @JsonProperty(
      "targetFolderRelativeToTask"
    ) Optional<String> targetFolderRelativeToTask,
    @JsonProperty("isArtifactList") Optional<Boolean> isArtifactList
  ) {
    super(
      name,
      filename,
      md5sum,
      filesize,
      s3Bucket,
      s3ObjectKey,
      targetFolderRelativeToTask,
      isArtifactList
    );
    this.artifactFilename = artifactFilename;
  }

  @Schema(description = "File name for the artifact")
  public String getArtifactFilename() {
    return artifactFilename;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    if (!super.equals(o)) {
      return false;
    }
    S3ArtifactSignature that = (S3ArtifactSignature) o;
    return Objects.equals(artifactFilename, that.artifactFilename);
  }

  @Override
  public int hashCode() {
    return Objects.hash(super.hashCode(), artifactFilename);
  }

  @Override
  public String toString() {
    return (
      "S3ArtifactSignature{" +
      "artifactFilename='" +
      artifactFilename +
      '\'' +
      "} " +
      super.toString()
    );
  }
}
